<!DOCTYPE HTML>
<html lang="en">

<head>
    <!--Setting-->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta http-equiv="Cache-Control" content="no-transform">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta name="apple-mobile-web-app-capable" content="Sanphone&#39;Blog">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,adress=no">
    <meta name="browsermode" content="application">
    <meta name="screen-orientation" content="portrait">
    <meta name="theme-version" content="1.3.0">
    <meta name="root" content="/blog/">
    <link rel="dns-prefetch" href="https://wuxiangfeng.gitee.io/sanphone.gitee.io">
    <!--SEO-->

<meta name="keywords" content="gitee pages,hexo" />


<meta name="description" content="1、安装hexo全局安装hexo
npm install -g hexo-cli


注意这里命令执行都在cmd终端中执行，最好别用power shell，会报错，我也不知道为啥，可能是环境变量..." />


<meta name="robots" content="all" />
<meta name="google" content="all" />
<meta name="googlebot" content="all" />
<meta name="verify" content="all" />
    <!--Title-->

<title>
    
    hexo和gitee搭建博客 |
    
    Sanphone&#39;Blog
</title>

<link rel="alternate" href="/atom.xml" title="Sanphone&#39;Blog" type="application/atom+xml">


<link rel="icon" href="/favicon.ico">

    


<link rel="stylesheet" href="/blog/css/bootstrap.min.css?rev=3.3.7.css">
<link rel="stylesheet" href="/blog/css/font-awesome.min.css?rev=4.7.0.css">
<link rel="stylesheet" href="/blog/css/style.css?rev=@@hash.css">

    
<div class="hide">
    <script type="text/javascript">
    var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
    document.write(unescape("%3Cspan class='cnzz_stat_icon_1263868967 hide' %3E%3Cscript%20src%3D%22https%3A%2F%2Fs95.cnzz.com%2Fz_stat.php%3Fweb_id%3D1272564536%22%3E%3C%2Fscript%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1263868967%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));
    </script>
</div>




    

<meta name="generator" content="Hexo 6.3.0"></head>
<!--[if lte IE 8]>
<style>
    html{ font-size: 1em }
</style>
<![endif]-->
<!--[if lte IE 9]>
<div style="ie">你使用的浏览器版本过低，为了你更好的阅读体验，请更新浏览器的版本或者使用其他现代浏览器，比如Chrome、Firefox、Safari等。</div>
<![endif]-->
<body>
    <header class="main-header"  style="background-image:url(
    https://hexo-theme-snippet-1251680922.cos.ap-beijing.myqcloud.com/img/banner.jpg)"
     >
    <div class="main-header-box">
        <a class="header-avatar" href="/" title='Sanphone'>
            <img src="/blog/img/avatar.jpg" alt="logo头像" class="img-responsive center-block">
        </a>
        <div class="branding">
            <!--<h2 class="text-hide">Snippet主题,从未如此简单有趣</h2>-->
            
            <img src="/blog/img/branding.png" alt="Snippet 博客主题" class="img-responsive center-block">
            
        </div>
    </div>
</header>
    <nav class="main-navigation">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="navbar-header"><span class="nav-toggle-button collapsed pull-right" data-toggle="collapse" data-target="#main-menu" id="mnav">
                        <span class="sr-only"></span>
                        <i class="fa fa-bars"></i>
                    </span>
                    <a class="navbar-brand" href="https://wuxiangfeng.gitee.io/sanphone.gitee.io">
                        Sanphone&#39;Blog</a>
                </div>
                <div class="collapse navbar-collapse" id="main-menu">
                    <ul class="menu">
                        
                        <li role="presentation" class="text-center">
                            <a href="/bolg"><i class="fa "></i>
                                主页</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/bolg/categories/前端/"><i class="fa "></i>
                                前端</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/bolg/categories/后端/"><i class="fa "></i>
                                后端</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/bolg/categories/移动端/"><i class="fa "></i>
                                移动端</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/bolg/categories/中间件/"><i class="fa "></i>
                                中间件</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/bolg/categories/工具/"><i class="fa "></i>
                                工具</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/bolg/archives/"><i class="fa "></i>
                                时间轴</a>
                        </li>
                        
                    </ul>
                </div>
            </div>
        </div>
    </div>
</nav>
    <section class="content-wrap">
        <div class="container">
            <div class="row">
                <main class="col-md-8 main-content m-post">
                    <p id="process"></p>
<article class="post">
    <div class="post-head">
        <h1 id="hexo和gitee搭建博客">
            
            hexo和gitee搭建博客
            
        </h1>
        <div class="post-meta">
    
    <span class="categories-meta fa-wrap">
        <i class="fa fa-folder-open-o"></i>
        <a class="category-link" href="/blog/categories/%E5%B7%A5%E5%85%B7/">工具</a>
    </span>
    
    
    <span class="fa-wrap">
        <i class="fa fa-tags"></i>
        <span class="tags-meta">
            
            <a class="tag-none-link" href="/blog/tags/gitee-pages/" rel="tag">gitee pages</a> <a class="tag-none-link" href="/blog/tags/hexo/" rel="tag">hexo</a>
            
        </span>
    </span>
    
    
    
    <span class="fa-wrap">
        <i class="fa fa-clock-o"></i>
        <span class="date-meta">
            2024/02/01</span>
    </span>
    
    <span class="fa-wrap">
        <i class="fa fa-eye"></i>
        <span id="busuanzi_value_page_pv"></span>
    </span>
    
    
</div>
        
        
    </div>
    
    <div class="post-body post-content">
        <h2 id="1、安装hexo"><a href="#1、安装hexo" class="headerlink" title="1、安装hexo"></a>1、安装hexo</h2><p>全局安装hexo</p>
<pre><code>npm install -g hexo-cli
</code></pre>
<blockquote>
<p>注意这里命令执行都在cmd终端中执行，最好别用power shell，会报错，我也不知道为啥，可能是环境变量没读到</p>
</blockquote>
<h2 id="2、初始化"><a href="#2、初始化" class="headerlink" title="2、初始化"></a>2、初始化</h2><p>建一个文件夹名字随意命名，例如blog，然后进入blog，执行初始化命令：</p>
<pre><code>hexo init
</code></pre>
<p>紧接着执行下面的命令,为了在github上clone npm的源码包</p>
<pre><code>npm install
</code></pre>
<p>再生成</p>
<pre><code>hexo g
</code></pre>
<p>测试</p>
<pre><code>hexo s
</code></pre>
<p>此时如果看到下面的输出信息，说明框架搭起来了：</p>
<pre><code>INFO  Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
</code></pre>
<p>打开浏览器，输入上面的地址，页面正常打开，说明目前一切都正常。</p>
<h2 id="3、部署到gitee"><a href="#3、部署到gitee" class="headerlink" title="3、部署到gitee"></a>3、部署到gitee</h2><ul>
<li>首先新建仓库，其他不多说，只要注意一点，仓库的命名规范：</li>
</ul>
<blockquote>
<p>仓库名.gitee.io</p>
</blockquote>
<ul>
<li>配置修改</li>
</ul>
<p>修改_config.yml文件</p>
<p>第一处：</p>
<pre><code>deploy:
  type: git
  repo: https://gitee.com/wuxiangfeng/sanphone.gitee.io.git # 配置仓库路径
  branch: master    # 分支
</code></pre>
<p>第二处：</p>
<pre><code>url: https://wuxiangfeng.gitee.io/sanphone.gitee.io/  # 这里是部署后的访问地址
root: .     # 这个点很重要， 如果不加，部署后页面会找不到样式
</code></pre>
<blockquote>
<p>我这里是部署到根目录,如果要部署到子目录,那这里的配置应该做相应的调整<br>例如 <a target="_blank" rel="noopener" href="http://example.com/blog%EF%BC%8C%E5%88%99%E8%AF%B7%E5%B0%86%E6%82%A8%E7%9A%84">http://example.com/blog，则请将您的</a> url 设为 <a target="_blank" rel="noopener" href="http://example.com/blog">http://example.com/blog</a> 并把 root 设为 &#x2F;blog&#x2F;。<br>当然gitee部署的时候的路径也需要配置,这个在gitee上部署的地方看得到,这里不细说</p>
</blockquote>
<ul>
<li>开始部署</li>
</ul>
<p>清理缓存</p>
<pre><code>hexo clean
</code></pre>
<p>使用 Hexo 生成静态文件快速而且简单</p>
<pre><code>hexo g
</code></pre>
<p>完成后部署</p>
<pre><code>hexo d
</code></pre>
<blockquote>
<p>这三条命令可以组合一起使用:</p>
<pre><code>hexo clean &amp;&amp; hexo g &amp;&amp; hexo d
</code></pre>
</blockquote>
<p>执行完成之后在giee的仓库下(顺利的话)可以看到我们的静态博客的文件.</p>
<ul>
<li>最后一步,gitee重新部署<br>进入到仓库下gitee pages的服务,点击<code>更新</code>即可。</li>
</ul>
<h2 id="遇到的错误"><a href="#遇到的错误" class="headerlink" title="遇到的错误"></a>遇到的错误</h2><ol>
<li>当执行hexo d的时候如果报下面的错：<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ERROR Deployer not found git</span><br></pre></td></tr></table></figure>
解决办法：<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install --save hexo-deployer-git</span><br></pre></td></tr></table></figure></li>
</ol>

    </div>
    
    <div class="post-footer">
        <div>
            
            转载声明：
            商业转载请联系作者获得授权,非商业转载请注明出处 © <a href="" target="_blank">Snippet</a>
            
            
        </div>
        <div>
            
        </div>
    </div>
</article>
<div class="article-nav prev-next-wrap clearfix">
    
    <a href="/blog/2024/02/01/ES-%E8%BD%BB%E9%87%8F%E6%9F%A5%E8%AF%A2-%E5%9F%BA%E4%BA%8EES5-6%E7%89%88%E6%9C%AC/" class="pre-post btn btn-default" title='ES-轻量查询---基于ES5.6版本'>
        <i class="fa fa-angle-left fa-fw"></i><span class="hidden-lg">上一篇</span>
        <span class="hidden-xs">
            ES-轻量查询---基于ES5.6版本</span>
    </a>
    
    
</div>

<div id="comments">
    
    
<div class="utteranc">
  
  <script
    src='https://utteranc.es/client.js'
    repo='shenliyang/snippet-comment'
    issue-term='pathname'
    issue-number=''
    theme='github-light'
    label=''
    crossorigin='anonymous'
    async
  ></script>
</div>



</div>

                </main>
                
                    <aside id="article-toc" role="navigation" class="col-md-4">
    <div class="widget">
        <h3 class="title">
            Table of Contents
        </h3>
        
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1%E3%80%81%E5%AE%89%E8%A3%85hexo"><span class="toc-text">1、安装hexo</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2%E3%80%81%E5%88%9D%E5%A7%8B%E5%8C%96"><span class="toc-text">2、初始化</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3%E3%80%81%E9%83%A8%E7%BD%B2%E5%88%B0gitee"><span class="toc-text">3、部署到gitee</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%81%87%E5%88%B0%E7%9A%84%E9%94%99%E8%AF%AF"><span class="toc-text">遇到的错误</span></a></li></ol>
        
    </div>
</aside>
                
            </div>
        </div>
    </section>
    <footer class="main-footer">
    <div class="container">
        <div class="row">
        </div>
    </div>
</footer>
<a id="back-to-top" class="icon-btn hide">
    <i class="fa fa-chevron-up"></i>
</a>
    <div class="copyright">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="busuanzi">
    
    Total:
    <strong id="busuanzi_value_site_pv">
        <i class="fa fa-spinner fa-spin"></i>
    </strong>
    &nbsp; | &nbsp;
    Visitors:
    <strong id="busuanzi_value_site_uv">
        <i class="fa fa-spinner fa-spin"></i>
    </strong>
    
</div>
            </div>
            <div class="col-sm-12">
                <span>Copyright &copy;
                    2017
                    
                </span> |
                <span>
                    Powered by <a href="//hexo.io" class="copyright-links" target="_blank" rel="nofollow">Hexo</a>
                </span> |
                <span>
                    Theme by <a href="//github.com/shenliyang/hexo-theme-snippet.git" class="copyright-links" target="_blank" rel="nofollow">Snippet</a>
                </span>
            </div>
        </div>
    </div>
</div>



<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>


<script src="/blog/js/app.js?rev=@@hash.js"></script>

</body>
</html>